package com.yue.springDemo.business.bean;

/**
 * 统一的返回bean
 */
public class ResponseResult {

    /**
     * 代码
     */
    private String code;

    /**
     * 消息
     */
    private String message;

    /**
     * 数据
     */
    private Object data;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 返回成功
     *
     * @param message 消息
     * @return 结果
     */
    public static ResponseResult success(String message) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage(message);
        return responseResult;
    }

    /**
     * 返回成功
     *
     * @param message 消息
     * @param data    数据
     * @return 结果
     */
    public static ResponseResult success(String message, Object data) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode("200");
        responseResult.setMessage(message);
        responseResult.setData(data);
        return responseResult;
    }

    /**
     * 返回异常
     *
     * @param code    返回code
     * @param message 消息
     * @return 结果
     */
    public static ResponseResult error(String code, String message) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(code);
        responseResult.setMessage(message);
        return responseResult;
    }

    @Override
    public String toString() {
        return "ResponseResult{" +
                "code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
